﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PowersourceUIToolkit;
using System.ComponentModel.Composition.Primitives;
using System.Reflection;
using UCL.Powersource;
using UCL.Powersource.TFS;
using UCL.Powersource.Mock;

namespace PowersourceUIToolkit
{
    public class DummyPowersourceBootStrapper : PowersourceBootstrapperBase
    {

        public new IUIManager UIManager { get { return base.UIManager; } set { base.UIManager = value; } }
        public new IStatisticManager StatisticManager { get { return base.StatisticManager; } set { base.StatisticManager = value; } }
        public new IReportingManager ReportingManager { get { return base.ReportingManager; } set { base.ReportingManager = value; } }
        public new IPowersourceExt IPowersourceExt { get { return base.IPowersourceExt; } set { base.IPowersourceExt = value; } }

        public new IVSEnv IVsEnv { get { return base.IVsEnv; } set { base.IVsEnv = value; } }
        public new ITfsTeamProjectCollectionFactory TfsTeamProjectCollectionFactory { get { return base.TfsTeamProjectCollectionFactory; } set { base.TfsTeamProjectCollectionFactory = value; } }
        public new IPackageConfigurationFactory PackageConfigurationFactory { get { return base.PackageConfigurationFactory; } set { base.PackageConfigurationFactory = value; } }
        public new Type[] TypesToLoad { get { return base.TypesToLoad; } set { base.TypesToLoad = value; } }
        public new Dictionary<Type, Type> DefaultInterfaceImplementationTypes { get { return base.DefaultInterfaceImplementationTypes; } set { base.DefaultInterfaceImplementationTypes = value; } }

        public new IStatisticManagerQueue StatisticManagerQueue { get { return base.StatisticManagerQueue; } set { base.StatisticManagerQueue = value; } }
        public new IRemoteBuilderQueue RemoteBuilderQueue { get { return base.RemoteBuilderQueue; } set { base.RemoteBuilderQueue = value; } }

        public void SetLog(ILog log)
        {
            base.Log = log;
        }

        public DummyPowersourceBootStrapper()
        {
            Debug.WriteLine("In {0} constructor, Initialization postponed", this.GetType().Name);
            ExtensibilityFiles.Add("SimoneUILibrary.dll");
            ExtensibilityFiles.Add("NobukoAnalyzer.dll");
        }


        protected override void Configure()
        {
            Debug.WriteLine("[{0}] : Configure", this);
            if (!base.DefaultInterfaceImplementationTypes.ContainsKey(typeof(IAnalysisBridge)))
            {
                base.DefaultInterfaceImplementationTypes.Add(typeof(IAnalysisBridge), typeof(DummyAnalysisBridge));
            }
            base.UIManager = UIManager ?? new DummyUIManager();
            base.Log = Log ?? LogManager.DefaultInstance;
            base.StatisticManager = StatisticManager ?? new DummyStatisticManager();
            base.ReportingManager = ReportingManager ?? new DummyReportingManager();
            base.IVsEnv = IVsEnv ?? new DummyVSEnv();
            base.TfsTeamProjectCollectionFactory = TfsTeamProjectCollectionFactory ?? new DummyTfsTeamProjectCollectionFactory();
            base.PackageConfigurationFactory = PackageConfigurationFactory ?? new DummyPackageConfigurationFactory();
            base.IPowersourceExt = IPowersourceExt ?? new DummyPowersourceExt();
            base.TypesToLoad = TypesToLoad ?? new Type[] { };
            base.Configure();

        }


        protected override bool ValidateAssembly(string assemblyFilename)
        {
            return true;
        }

        public void SetExtensibilityFiles(IEnumerable<string> extensibilityFiles)
        {
            if (this.ExtensibilityFiles == null) this.ExtensibilityFiles = new List<string>();
            this.ExtensibilityFiles.AddRange(extensibilityFiles); //= ExtensibilityDirectory;
        }
    }
}
